package com.hjm.mall.service.impl;

import com.hjm.mall.api.vo.GoodsListVO;
import com.hjm.mall.dao.GoodsMapper;
import com.hjm.mall.entity.Goods;
import com.hjm.mall.service.GoodsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    GoodsMapper goodsMapper;
    @Override
    public Goods getGoodsById(int id) {
        return goodsMapper.getGoodsById(id);
    }

    @Override
    public List<Goods> getGoodsByStoreId(int storeId) {
        return goodsMapper.getGoodsByStoreId(storeId);
    }

    @Override
    public List<Goods> getRandomGoodsList(int num) {
        return goodsMapper.getRandomGoods(num);
    }

    public List<GoodsListVO> getGoodsVOByStoreId(int storeId){
        List<GoodsListVO> goodsListVOList = new ArrayList<>();
        List<Goods> goodsByStoreId = goodsMapper.getGoodsByStoreId(storeId);
        GoodsListVO goodsListVO;
        for (Goods goods:goodsByStoreId){
            goodsListVO = new GoodsListVO();
            BeanUtils.copyProperties(goods,goodsListVO);
//            goodsListVO.setId(goods.getId());
//            goodsListVO.setIcon(goods.getIcon());
//            goodsListVO.setName(goods.getName());
//            goodsListVO.setPrice(goods.getPrice());
            goodsListVOList.add(goodsListVO);
        }
        return goodsListVOList;
    }
}
